package com.yunhe.tianhe.rentcars.service.zuche.impl;


import com.yunhe.tianhe.commons.dto.Pageable;
import com.yunhe.tianhe.rentcars.dao.zuche.CarOrderDao;
import com.yunhe.tianhe.rentcars.entity.zuche.CarOrder;
import com.yunhe.tianhe.rentcars.service.zuche.CarOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class CarOrderServiceImpl implements CarOrderService {

    @Autowired
    private CarOrderDao carOrderDao;

    @Override
    public Pageable<CarOrder> findPage(Integer offset, Integer limit,String mobile,Long orderid) {
        Pageable<CarOrder> pageable = new Pageable<>();
        pageable.setPage(offset + 1);
        pageable.setSize(limit);
        int count = carOrderDao.pageCount();
        List<CarOrder> data = null;
        if(count > 0) {
            data = carOrderDao.pageList(offset, limit,mobile,orderid);
        }
        pageable.setTotal(new Long(count));
        pageable.setRows(data);
        return pageable;
    }

    @Override
    public CarOrder findMsgByOrderid(String orderid) {
        CarOrder carOrder = carOrderDao.findMsgByOrderid(orderid);


        return carOrder;
    }

    @Override
    public void save(CarOrder carOrder, HttpServletRequest request) {
        carOrderDao.save(carOrder);
        request.getSession().setAttribute("oid",carOrder.getOrderid());

    }

    @Override
    public void update(Long orderid) {
        carOrderDao.update(orderid);
    }
}
